﻿Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.ComponentModel
Imports System.Data
Imports System.Data.Sql
Imports System.Data.SqlClient


' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
' <System.Web.Script.Services.ScriptService()> _
<System.Web.Services.WebService(Namespace:="http://tempuri.org/")> _
<System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<ToolboxItem(False)> _
Public Class EventSales
    Inherits System.Web.Services.WebService

    Dim oSQLTran As SqlTransaction
    Dim oSQLConnection As SqlConnection = New SqlConnection
    Dim oSQLCommand As SqlCommand = New SqlCommand



    <WebMethod()> _
    Public Function Get_SalesQuotationData(ByVal sSalesQuotNum As String, ByVal sCustomerName As String, ByVal sContPerName As String) As DataSet

        Dim sErrDesc As String = String.Empty
        Dim sFuncName As String = String.Empty
        Dim oSalesQuotation As AE_EASIPOS_INTEGRATION_DLL.clsSalesQuotationData = New AE_EASIPOS_INTEGRATION_DLL.clsSalesQuotationData

        Try
            sFuncName = "Get_SalesQuotationData()"
            p_iDebugMode = 1
            If p_iDebugMode = DEBUG_ON Then Call WriteToLogFile_Debug("Starting Function", sFuncName)


            'Getting the Parameter Values from App Cofig File
            If p_iDebugMode = DEBUG_ON Then Call WriteToLogFile_Debug("Calling GetSystemIntializeInfo()", sFuncName)
            If GetSystemIntializeInfo(p_oCompDef, sErrDesc) <> RTN_SUCCESS Then Throw New ArgumentException(sErrDesc)

            ''Function to connect the Company
            'If p_iDebugMode = DEBUG_ON Then Call WriteToLogFile_Debug("Calling ConnectToTargetCompany()", sFuncName)
            'If ConnectToTargetCompany(p_oCompany, sErrDesc) <> RTN_SUCCESS Then Throw New ArgumentException(sErrDesc)

            P_sConString = String.Empty
            P_sConString = "Data Source=" & p_oCompDef.p_sServerName & ";Initial Catalog=" & p_oCompDef.p_sDataBaseName & ";User ID=" & p_oCompDef.p_sDBUserName & "; Password=" & p_oCompDef.p_sDBPassword

            If p_iDebugMode = DEBUG_ON Then Call WriteToLogFile_Debug("Calling SalesQuotationData_Open()", sFuncName)
            Get_SalesQuotationData = oSalesQuotation.SalesQuotationData_Open(sSalesQuotNum, sCustomerName, sContPerName, P_sConString)

            If p_iDebugMode = DEBUG_ON Then Call WriteToLogFile_Debug("Completed with SUCCESS", sFuncName)

        Catch ex As Exception
            Return Nothing
            If p_iDebugMode = DEBUG_ON Then Call WriteToLogFile_Debug("Completed with ERROR", sFuncName)
            WriteToLogFile(ex.Message, sFuncName)

        End Try

    End Function

    <WebMethod()> _
    Public Function Get_SalesQuotationData_Closed() As DataSet

        Dim sErrDesc As String = String.Empty
        Dim sFuncName As String = String.Empty
        Dim oSalesQuotation As AE_EASIPOS_INTEGRATION_DLL.clsSalesQuotationData = New AE_EASIPOS_INTEGRATION_DLL.clsSalesQuotationData

        Try
            p_iDebugMode = 1
            sFuncName = "Get_SalesQuotationData_Closed()"
            If p_iDebugMode = DEBUG_ON Then Call WriteToLogFile_Debug("Starting Function", sFuncName)


            'Getting the Parameter Values from App Cofig File
            If p_iDebugMode = DEBUG_ON Then Call WriteToLogFile_Debug("Calling GetSystemIntializeInfo()", sFuncName)
            If GetSystemIntializeInfo(p_oCompDef, sErrDesc) <> RTN_SUCCESS Then Throw New ArgumentException(sErrDesc)

            ''Function to connect the Company
            'If p_iDebugMode = DEBUG_ON Then Call WriteToLogFile_Debug("Calling ConnectToTargetCompany()", sFuncName)
            'If ConnectToTargetCompany(p_oCompany, sErrDesc) <> RTN_SUCCESS Then Throw New ArgumentException(sErrDesc)

            P_sConString = String.Empty
            P_sConString = "Data Source=" & p_oCompDef.p_sServerName & ";Initial Catalog=" & p_oCompDef.p_sDataBaseName & ";User ID=" & p_oCompDef.p_sDBUserName & "; Password=" & p_oCompDef.p_sDBPassword

            If p_iDebugMode = DEBUG_ON Then Call WriteToLogFile_Debug("Calling SalesQuotationData_Closed()", sFuncName)
            Get_SalesQuotationData_Closed = oSalesQuotation.SalesQuotationData_Closed(P_sConString)

            If p_iDebugMode = DEBUG_ON Then Call WriteToLogFile_Debug("Completed with SUCCESS", sFuncName)

        Catch ex As Exception
            Return Nothing
            If p_iDebugMode = DEBUG_ON Then Call WriteToLogFile_Debug("Completed with ERROR", sFuncName)
            WriteToLogFile(ex.Message, sFuncName)

        End Try

    End Function

    <WebMethod()> _
    Public Function Get_SalesOrderData(ByVal sOutlet As String, ByVal sCustName As String, ByVal sConPerName As String, ByVal dtEventDate As Date) As DataSet

        Dim sErrDesc As String = String.Empty
        Dim sFuncName As String = String.Empty
        Dim oSalesOrder As AE_EASIPOS_INTEGRATION_DLL.clsSalesOrderData = New AE_EASIPOS_INTEGRATION_DLL.clsSalesOrderData

        Try
            p_iDebugMode = 1
            sFuncName = "Get_SalesOrderData()"
            If p_iDebugMode = DEBUG_ON Then Call WriteToLogFile_Debug("Starting Function", sFuncName)


            'Getting the Parameter Values from App Cofig File
            If p_iDebugMode = DEBUG_ON Then Call WriteToLogFile_Debug("Calling GetSystemIntializeInfo()", sFuncName)
            If GetSystemIntializeInfo(p_oCompDef, sErrDesc) <> RTN_SUCCESS Then Throw New ArgumentException(sErrDesc)

            ''Function to connect the Company
            'If p_iDebugMode = DEBUG_ON Then Call WriteToLogFile_Debug("Calling ConnectToTargetCompany()", sFuncName)
            'If ConnectToTargetCompany(p_oCompany, sErrDesc) <> RTN_SUCCESS Then Throw New ArgumentException(sErrDesc)

            P_sConString = String.Empty
            P_sConString = "Data Source=" & p_oCompDef.p_sServerName & ";Initial Catalog=" & p_oCompDef.p_sDataBaseName & ";User ID=" & p_oCompDef.p_sDBUserName & "; Password=" & p_oCompDef.p_sDBPassword

            If p_iDebugMode = DEBUG_ON Then Call WriteToLogFile_Debug("Calling SalesOrderData()", sFuncName)
            Get_SalesOrderData = oSalesOrder.SalesOrderData(sOutlet, sCustName, sConPerName, dtEventDate, P_sConString)

            If p_iDebugMode = DEBUG_ON Then Call WriteToLogFile_Debug("Completed with SUCCESS", sFuncName)
        Catch ex As Exception
            Return Nothing
            If p_iDebugMode = DEBUG_ON Then Call WriteToLogFile_Debug("Completed with ERROR", sFuncName)
            WriteToLogFile(ex.Message, sFuncName)

        End Try

    End Function

    <WebMethod()>
    Public Function UpdateEvent(ByVal oDataset As DataSet, ByRef sErrDesc As String) As Boolean

        Dim sFuncName As String = String.Empty
        Dim oSQLConnection As SqlConnection = New SqlConnection
        Dim oDTHeader As DataTable = New DataTable
        Dim oDTDetails As DataTable = New DataTable
        Dim oDTPayment As DataTable = New DataTable


        Try

            p_iDebugMode = 1
            sFuncName = "UpdateEvent()"
            If p_iDebugMode = DEBUG_ON Then Call WriteToLogFile_Debug("Starting Function", sFuncName)

            oDTHeader = oDataset.Tables(0)
            oDTDetails = oDataset.Tables(1)
            oDTPayment = oDataset.Tables(2)


            'Getting the Parameter Values from App Cofig File
            If p_iDebugMode = DEBUG_ON Then Call WriteToLogFile_Debug("Calling GetSystemIntializeInfo()", sFuncName)
            If GetSystemIntializeInfo(p_oCompDef, sErrDesc) <> RTN_SUCCESS Then Throw New ArgumentException(sErrDesc)

            P_sConString = String.Empty
            P_sConString = "Data Source=" & p_oCompDef.p_sServerName & ";Initial Catalog=" & p_oCompDef.p_sINTDBName & ";User ID=" & p_oCompDef.p_sDBUserName & "; Password=" & p_oCompDef.p_sDBPassword


            Try
                oSQLConnection = New SqlConnection(P_sConString)
                If oSQLConnection.State = ConnectionState.Closed Then
                    oSQLConnection.Open()
                End If
                oSQLTran = oSQLConnection.BeginTransaction

                Dim sQuery As String = String.Empty


                sQuery = "INSERT INTO SalesOrderHdr([OrderNumber],[CustomerAccountNo] ,[CustomerFullName],[ContactName],[BillingAddress],[Telephone] ,[Email] ,[EventOrderNumber]" & _
                        " ,[PersonInCharge] ,[DistributionDate],[EventDate] ,[EventStartTime] ,[EventTimeEnd] ,[FoodTimeStart] ,[FoodTimeEnd] ,[BvgTimeStart] ,[BvgTimeEnd]" & _
                        " ,[EventVenue] ,[EventFunction] ,[OutletCode] ,[EventSetup]  ,[GTDAttendance]  ,[EXPAttendance] ,[AudioVisual] ,[BanquetOperation] ,[Linens] " & _
                        " ,[Signage] ,[FinanceInstructions],[ReqDownPaymtAmt],[RevenueCenter] ,[GrossAmount] ,[PaidToDate]  ,[EventStatus] ,[RevenueCenterName]"

                sQuery += ") VALUES ("

                sQuery += "@OrderNumber,@CustomerAccountNo,@CustomerFullName,@ContactName,@BillingAddress,@Telephone,@Email,@EventOrderNumber,@PersonInCharge, " & _
                    " DistributionDate,@EventDate,@EventStartTime,@EventTimeEnd,@FoodTimeStart,@FoodTimeEnd,@BvgTimeStart,@BvgTimeEnd,@EventVenue,@EventFunction," & _
                    " @OutletCode,@EventSetup,@GTDAttendance,@EXPAttendance,@AudioVisual,@BanquetOperation,@Linens,@Signage,@FinanceInstructions,@ReqDownPaymtAmt, " & _
                    " @RevenueCenter,@GrossAmount,@PaidToDate,@EventStatus,@RevenueCenterName);"

                oSQLCommand = New SqlCommand
                oSQLCommand.Connection = oSQLConnection
                oSQLCommand.CommandText = sQuery
                oSQLCommand.Transaction = oSQLTran
                oSQLCommand.CommandTimeout = 180

                '' oSQLCommand.Parameters.Add("@LUPDATE", SqlDbType.Date).Value = GET_CURRENT_DATE()

                oSQLCommand.Parameters.Add("@OrderNumber", SqlDbType.Int).Value = CInt(oDTHeader.Rows(0)("OrderNumber").ToString())
                oSQLCommand.Parameters.Add("@CustomerAccountNo", SqlDbType.NChar).Value = oDTHeader.Rows(0)("CustomerAccountNo").ToString()
                oSQLCommand.Parameters.Add("@CustomerFullName", SqlDbType.NVarChar).Value = oDTHeader.Rows(0)("CustomerFullName").ToString()
                oSQLCommand.Parameters.Add("@ContactName", SqlDbType.NVarChar).Value = oDTHeader.Rows(0)("ContactName").ToString()
                oSQLCommand.Parameters.Add("@BillingAddress", SqlDbType.NVarChar).Value = oDTHeader.Rows(0)("BillingAddress").ToString()
                oSQLCommand.Parameters.Add("@Telephone", SqlDbType.NVarChar).Value = oDTHeader.Rows(0)("Telephone").ToString()
                oSQLCommand.Parameters.Add("@Email", SqlDbType.NVarChar).Value = oDTHeader.Rows(0)("Email").ToString()
                oSQLCommand.Parameters.Add("@EventOrderNumber", SqlDbType.Int).Value = oDTHeader.Rows(0)("EventOrderNumber").ToString()
                oSQLCommand.Parameters.Add("@PersonInCharge", SqlDbType.NVarChar).Value = oDTHeader.Rows(0)("PersonInCharge").ToString()
                oSQLCommand.Parameters.Add("@DistributionDate", SqlDbType.Date).Value = oDTHeader.Rows(0)("DistributionDate").ToString()
                oSQLCommand.Parameters.Add("@EventDate", SqlDbType.Date).Value = oDTHeader.Rows(0)("EventDate").ToString()
                oSQLCommand.Parameters.Add("@EventStartTime", SqlDbType.Int).Value = oDTHeader.Rows(0)("EventStartTime").ToString()
                oSQLCommand.Parameters.Add("@EventTimeEnd", SqlDbType.Int).Value = oDTHeader.Rows(0)("EventTimeEnd").ToString()
                oSQLCommand.Parameters.Add("@FoodTimeStart", SqlDbType.Int).Value = oDTHeader.Rows(0)("FoodTimeStart").ToString()
                oSQLCommand.Parameters.Add("@FoodTimeEnd", SqlDbType.Int).Value = oDTHeader.Rows(0)("FoodTimeEnd").ToString()
                oSQLCommand.Parameters.Add("@BvgTimeStart", SqlDbType.Time).Value = oDTHeader.Rows(0)("BvgTimeStart").ToString()
                oSQLCommand.Parameters.Add("@BvgTimeEnd", SqlDbType.Int).Value = oDTHeader.Rows(0)("BvgTimeEnd").ToString()
                oSQLCommand.Parameters.Add("@EventVenue", SqlDbType.NVarChar).Value = oDTHeader.Rows(0)("EventVenue").ToString()
                oSQLCommand.Parameters.Add("@EventFunction", SqlDbType.NVarChar).Value = oDTHeader.Rows(0)("EventFunction").ToString()
                oSQLCommand.Parameters.Add("@OutletCode", SqlDbType.NVarChar).Value = oDTHeader.Rows(0)("OutletCode").ToString()
                oSQLCommand.Parameters.Add("@EventSetup", SqlDbType.NVarChar).Value = oDTHeader.Rows(0)("EventSetup").ToString()
                oSQLCommand.Parameters.Add("@GTDAttendance", SqlDbType.Int).Value = oDTHeader.Rows(0)("GTDAttendance").ToString()
                oSQLCommand.Parameters.Add("@EXPAttendance", SqlDbType.Int).Value = oDTHeader.Rows(0)("EXPAttendance").ToString()
                oSQLCommand.Parameters.Add("@AudioVisual", SqlDbType.NText).Value = oDTHeader.Rows(0)("AudioVisual").ToString()
                oSQLCommand.Parameters.Add("@BanquetOperation", SqlDbType.NText).Value = oDTHeader.Rows(0)("BanquetOperation").ToString()
                oSQLCommand.Parameters.Add("@Linens", SqlDbType.NText).Value = oDTHeader.Rows(0)("Linens").ToString()
                oSQLCommand.Parameters.Add("@Signage", SqlDbType.NText).Value = oDTHeader.Rows(0)("Signage").ToString()
                oSQLCommand.Parameters.Add("@FinanceInstructions", SqlDbType.NChar).Value = oDTHeader.Rows(0)("FinanceInstructions").ToString()
                oSQLCommand.Parameters.Add("@ReqDownPaymtAmt", SqlDbType.Float).Value = oDTHeader.Rows(0)("ReqDownPaymtAmt").ToString()
                oSQLCommand.Parameters.Add("@RevenueCenter", SqlDbType.NVarChar).Value = oDTHeader.Rows(0)("RevenueCenter").ToString()
                oSQLCommand.Parameters.Add("@GrossAmount", SqlDbType.Float).Value = (oDTHeader.Rows(0)("GrossAmount").ToString())
                oSQLCommand.Parameters.Add("@PaidToDate", SqlDbType.Float).Value = oDTHeader.Rows(0)("PaidToDate").ToString()
                oSQLCommand.Parameters.Add("@EventStatus", SqlDbType.Char).Value = oDTHeader.Rows(0)("EventStatus").ToString()
                oSQLCommand.Parameters.Add("@RevenueCenterName", SqlDbType.NVarChar).Value = oDTHeader.Rows(0)("RevenueCenterName").ToString()


                oSQLCommand.ExecuteNonQuery()



                For iDetailCount = 0 To oDTDetails.Rows.Count - 1 ''Step i + 1

                    sQuery = "INSERT INTO SalesOrderDET( [OrderNumber] ,[OrderLine],[VisualOrder],[SalesOultlet] ,[ProductCode],[PrtOnRcpt] ,[Price]  ,[Quantity] ,[GrossAmount] ,[RevenueCenter] ,[LineText] "
                    sQuery += ") VALUES ("
                    sQuery += "@OrderNumber,@OrderLine,@VisualOrder,@SalesOultlet,@ProductCode,@PrtOnRcpt,@Price,@Quantity,@GrossAmount,@RevenueCenter,@LineText );"

                    oSQLCommand = New SqlCommand
                    If oSQLConnection.State = ConnectionState.Closed Then
                        oSQLConnection.Open()
                    End If

                    oSQLCommand.Connection = oSQLConnection
                    oSQLCommand.CommandText = sQuery
                    oSQLCommand.Transaction = oSQLTran
                    oSQLCommand.CommandTimeout = 180


                    oSQLCommand.Parameters.Add("@OrderNumber", SqlDbType.Int).Value = oDTDetails.Rows(iDetailCount)("OrderNumber").ToString()
                    oSQLCommand.Parameters.Add("@OrderLine", SqlDbType.Int).Value = oDTDetails.Rows(iDetailCount)("OrderLine").ToString()
                    oSQLCommand.Parameters.Add("@VisualOrder", SqlDbType.Int).Value = oDTDetails.Rows(iDetailCount)("VisualOrder").ToString()
                    oSQLCommand.Parameters.Add("@SalesOultlet", SqlDbType.NVarChar).Value = oDTDetails.Rows(iDetailCount)("SalesOultlet").ToString()
                    oSQLCommand.Parameters.Add("@ProductCode", SqlDbType.NVarChar).Value = oDTDetails.Rows(iDetailCount)("ProductCode").ToString()
                    oSQLCommand.Parameters.Add("@PrtOnRcpt", SqlDbType.NChar).Value = oDTDetails.Rows(iDetailCount)("PrtOnRcpt").ToString()
                    oSQLCommand.Parameters.Add("@Price", SqlDbType.Decimal).Value = oDTDetails.Rows(iDetailCount)("Price").ToString()
                    oSQLCommand.Parameters.Add("@Quantity", SqlDbType.Decimal).Value = oDTDetails.Rows(iDetailCount)("Quantity").ToString()
                    oSQLCommand.Parameters.Add("@GrossAmount", SqlDbType.Decimal).Value = oDTDetails.Rows(iDetailCount)("GrossAmount").ToString()
                    oSQLCommand.Parameters.Add("@RevenueCenter", SqlDbType.NVarChar).Value = oDTDetails.Rows(iDetailCount)("RevenueCenter").ToString()
                    oSQLCommand.Parameters.Add("@LineText", SqlDbType.NVarChar).Value = oDTDetails.Rows(iDetailCount)("LineText").ToString()



                    oSQLCommand.ExecuteNonQuery()

                Next
                For iPayCount = 0 To oDTPayment.Rows.Count - 1 '--'Step i + 1

                    sQuery = "INSERT INTO SalesOrderPymt (SalesOrderNum,TenderCode, PaymentAmount, PaymentDate,Outlet, POSNo ,ChqNo"
                    sQuery += ") VALUES ("
                    sQuery += "@SalesOrderNum,@TenderCode,@PaymentAmount,@PaymentDate,@Outlet,@POSNo,@ChqNo);"

                    oSQLCommand = New SqlCommand
                    If oSQLConnection.State = ConnectionState.Closed Then
                        oSQLConnection.Open()
                    End If
                    oSQLCommand.Transaction = oSQLTran
                    oSQLCommand.Connection = oSQLConnection
                    oSQLCommand.CommandText = sQuery
                    oSQLCommand.CommandTimeout = 180

                    oSQLCommand.Parameters.Add("@SalesOrderNum", SqlDbType.Int).Value = oDTPayment.Rows(iPayCount)("SalesOrderNum").ToString()
                    oSQLCommand.Parameters.Add("@TenderCode", SqlDbType.NVarChar).Value = oDTPayment.Rows(iPayCount)("TenderCode").ToString()
                    oSQLCommand.Parameters.Add("@PaymentAmount", SqlDbType.Decimal).Value = oDTPayment.Rows(iPayCount)("PaymentAmount").ToString()
                    oSQLCommand.Parameters.Add("@PaymentDate", SqlDbType.Date).Value = oDTPayment.Rows(iPayCount)("PaymentDate").ToString()
                    oSQLCommand.Parameters.Add("@Outlet", SqlDbType.NVarChar).Value = oDTPayment.Rows(iPayCount)("Outlet").ToString()
                    oSQLCommand.Parameters.Add("@POSNo", SqlDbType.NVarChar).Value = oDTPayment.Rows(iPayCount)("POSNo").ToString()
                    oSQLCommand.Parameters.Add("@ChqNo", SqlDbType.NVarChar).Value = oDTPayment.Rows(iPayCount)("ChqNo").ToString()


                    oSQLCommand.ExecuteNonQuery()
                Next

                oSQLTran.Commit()

            Catch ex As Exception
                oSQLTran.Rollback()
                sErrDesc = ex.Message.ToString()
                Throw New ArgumentException(sErrDesc)
            End Try

            oSQLConnection.Dispose()
            oSQLCommand.Dispose()

            If p_iDebugMode = DEBUG_ON Then Call WriteToLogFile_Debug("Completed with SUCCESS", sFuncName)

            UpdateEvent = True & " - " & sErrDesc

        Catch ex As Exception
            sErrDesc = ex.Message.ToString()
            If p_iDebugMode = DEBUG_ON Then Call WriteToLogFile_Debug("Completed with ERROR", sFuncName)
            WriteToLogFile(ex.Message, sFuncName)
            UpdateEvent = False & " - " & sErrDesc
        End Try
    End Function

    <WebMethod()>
    Public Function EventDeposit(ByVal oDataset As DataSet, ByRef sErrDesc As String) As Boolean

        Dim sFuncName As String = String.Empty
        Dim oSQLConnection As SqlConnection = New SqlConnection
        Dim sQuery As String = String.Empty
        Dim oDTPayment As DataTable = New DataTable


        Try

            p_iDebugMode = 1
            sFuncName = "EventDeposit()"
            If p_iDebugMode = DEBUG_ON Then Call WriteToLogFile_Debug("Starting Function", sFuncName)

            oDTPayment = oDataset.Tables(0)


            'Getting the Parameter Values from App Cofig File
            If p_iDebugMode = DEBUG_ON Then Call WriteToLogFile_Debug("Calling GetSystemIntializeInfo()", sFuncName)
            If GetSystemIntializeInfo(p_oCompDef, sErrDesc) <> RTN_SUCCESS Then Throw New ArgumentException(sErrDesc)

            P_sConString = String.Empty
            P_sConString = "Data Source=" & p_oCompDef.p_sServerName & ";Initial Catalog=" & p_oCompDef.p_sINTDBName & ";User ID=" & p_oCompDef.p_sDBUserName & "; Password=" & p_oCompDef.p_sDBPassword


            Try
                oSQLConnection = New SqlConnection(P_sConString)
                If oSQLConnection.State = ConnectionState.Closed Then
                    oSQLConnection.Open()
                End If
                oSQLTran = oSQLConnection.BeginTransaction


                For iPayCount = 0 To oDTPayment.Rows.Count - 1 '--'Step i + 1

                    sQuery = "INSERT INTO EventDeposit (SalesQuotNum,TenderCode, PaymentAmount, PaymentDate,Outlet, POSNo ,ChqNo"
                    sQuery += ") VALUES ("
                    sQuery += "@SalesQuotNum,@TenderCode,@PaymentAmount,@PaymentDate,@Outlet,@POSNo,@ChqNo);"

                    oSQLCommand = New SqlCommand
                    If oSQLConnection.State = ConnectionState.Closed Then
                        oSQLConnection.Open()
                    End If
                    oSQLCommand.Transaction = oSQLTran
                    oSQLCommand.Connection = oSQLConnection
                    oSQLCommand.CommandText = sQuery
                    oSQLCommand.CommandTimeout = 180

                    oSQLCommand.Parameters.Add("@SalesQuotNum", SqlDbType.Int).Value = oDTPayment.Rows(iPayCount)("SalesQuotNum").ToString()
                    oSQLCommand.Parameters.Add("@TenderCode", SqlDbType.NVarChar).Value = oDTPayment.Rows(iPayCount)("TenderCode").ToString()
                    oSQLCommand.Parameters.Add("@PaymentAmount", SqlDbType.Decimal).Value = oDTPayment.Rows(iPayCount)("PaymentAmount").ToString()
                    oSQLCommand.Parameters.Add("@PaymentDate", SqlDbType.Date).Value = oDTPayment.Rows(iPayCount)("PaymentDate").ToString()
                    oSQLCommand.Parameters.Add("@Outlet", SqlDbType.NVarChar).Value = oDTPayment.Rows(iPayCount)("Outlet").ToString()
                    oSQLCommand.Parameters.Add("@POSNo", SqlDbType.NVarChar).Value = oDTPayment.Rows(iPayCount)("POSNo").ToString()
                    oSQLCommand.Parameters.Add("@ChqNo", SqlDbType.NVarChar).Value = oDTPayment.Rows(iPayCount)("ChqNo").ToString()


                    oSQLCommand.ExecuteNonQuery()
                Next

                oSQLTran.Commit()

            Catch ex As Exception
                oSQLTran.Rollback()
                sErrDesc = ex.Message.ToString()
                Throw New ArgumentException(sErrDesc)
            End Try

            oSQLConnection.Dispose()
            oSQLCommand.Dispose()

            If p_iDebugMode = DEBUG_ON Then Call WriteToLogFile_Debug("Completed with SUCCESS", sFuncName)
            EventDeposit = True & " - " & sErrDesc

        Catch ex As Exception
            sErrDesc = ex.Message.ToString()

            If p_iDebugMode = DEBUG_ON Then Call WriteToLogFile_Debug("Completed with ERROR", sFuncName)
            WriteToLogFile(ex.Message, sFuncName)
            EventDeposit = False & " - " & sErrDesc
        End Try
    End Function

    '<WebMethod()> _
    'Public Function Update_SalesOrder(ByRef oDataSet As DataSet) As String

    '    Dim sErrDesc As String = String.Empty
    '    Dim sFuncName As String = String.Empty
    '    Dim oSalesOrder As AE_EASIPOS_INTEGRATION_DLL.clsSalesOrderData = New AE_EASIPOS_INTEGRATION_DLL.clsSalesOrderData

    '    Try
    '        p_iDebugMode = 1
    '        sFuncName = "Update_SalesOrder()"
    '        If p_iDebugMode = DEBUG_ON Then Call WriteToLogFile_Debug("Starting Function", sFuncName)


    '        'Getting the Parameter Values from App Cofig File
    '        If p_iDebugMode = DEBUG_ON Then Call WriteToLogFile_Debug("Calling GetSystemIntializeInfo()", sFuncName)
    '        If GetSystemIntializeInfo(p_oCompDef, sErrDesc) <> RTN_SUCCESS Then Throw New ArgumentException(sErrDesc)

    '        'Function to connect the Company
    '        If p_oCompany Is Nothing Then
    '            If p_iDebugMode = DEBUG_ON Then Call WriteToLogFile_Debug("Calling ConnectToTargetCompany()", sFuncName)
    '            If ConnectToTargetCompany(p_oCompany, sErrDesc) <> RTN_SUCCESS Then Throw New ArgumentException(sErrDesc)
    '        End If


    '        If p_iDebugMode = DEBUG_ON Then Call WriteToLogFile_Debug("Start the Company Transaction ", sFuncName)

    '        If p_oCompany.InTransaction = False Then p_oCompany.StartTransaction()

    '        If p_iDebugMode = DEBUG_ON Then Call WriteToLogFile_Debug("Calling Update_SalesOrder()", sFuncName)

    '        If (oSalesOrder.Update_SalesOrder(oDataSet, p_oCompany, sErrDesc)) <> RTN_SUCCESS Then Throw New ArgumentException(sErrDesc)

    '        If p_oCompany.InTransaction = True Then p_oCompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_Commit)
    '        If p_iDebugMode = DEBUG_ON Then Call WriteToLogFile_Debug("Committed the Transaction ", sFuncName)

    '        If p_iDebugMode = DEBUG_ON Then Call WriteToLogFile_Debug("Completed with SUCCESS", sFuncName)

    '        Return "SUCCESS"

    '    Catch ex As Exception
    '        If p_oCompany.InTransaction = True Then p_oCompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_RollBack)
    '        If p_iDebugMode = DEBUG_ON Then Call WriteToLogFile_Debug("Rollback the Transaction ", sFuncName)
    '        If p_iDebugMode = DEBUG_ON Then Call WriteToLogFile_Debug("Completed with ERROR", sFuncName)
    '        WriteToLogFile(ex.Message, sFuncName)
    '        Return ex.Message
    '    End Try

    'End Function

    '<WebMethod()> _
    'Public Function AdvancePayment(ByRef oDataSet As DataSet) As String

    '    Dim sErrDesc As String = String.Empty
    '    Dim sFuncName As String = String.Empty
    '    Dim oARDownpayment As AE_EASIPOS_INTEGRATION_DLL.ClsARDownpayment = New AE_EASIPOS_INTEGRATION_DLL.ClsARDownpayment

    '    Try
    '        p_iDebugMode = 1
    '        sFuncName = "AdvancePayment()"
    '        If p_iDebugMode = DEBUG_ON Then Call WriteToLogFile_Debug("Starting Function", sFuncName)


    '        'Getting the Parameter Values from App Cofig File
    '        If p_iDebugMode = DEBUG_ON Then Call WriteToLogFile_Debug("Calling GetSystemIntializeInfo()", sFuncName)
    '        If GetSystemIntializeInfo(p_oCompDef, sErrDesc) <> RTN_SUCCESS Then Throw New ArgumentException(sErrDesc)

    '        'Function to connect the Company
    '        If p_oCompany Is Nothing Then
    '            If p_iDebugMode = DEBUG_ON Then Call WriteToLogFile_Debug("Calling ConnectToTargetCompany()", sFuncName)
    '            If ConnectToTargetCompany(p_oCompany, sErrDesc) <> RTN_SUCCESS Then Throw New ArgumentException(sErrDesc)
    '        End If


    '        If p_iDebugMode = DEBUG_ON Then Call WriteToLogFile_Debug("Start the Company Transaction ", sFuncName)

    '        If p_oCompany.InTransaction = False Then p_oCompany.StartTransaction()

    '        If p_iDebugMode = DEBUG_ON Then Call WriteToLogFile_Debug("Calling AR_Downpayment()", sFuncName)

    '        If (oARDownpayment.AR_Downpayment(oDataSet, p_oCompany, sErrDesc)) <> RTN_SUCCESS Then Throw New ArgumentException(sErrDesc)

    '        If p_oCompany.InTransaction = True Then p_oCompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_Commit)
    '        If p_iDebugMode = DEBUG_ON Then Call WriteToLogFile_Debug("Committed the Transaction ", sFuncName)

    '        If p_iDebugMode = DEBUG_ON Then Call WriteToLogFile_Debug("Completed with SUCCESS", sFuncName)

    '        Return "SUCCESS"

    '    Catch ex As Exception
    '        If p_oCompany.InTransaction = True Then p_oCompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_RollBack)
    '        If p_iDebugMode = DEBUG_ON Then Call WriteToLogFile_Debug("Rollback the Transaction ", sFuncName)
    '        If p_iDebugMode = DEBUG_ON Then Call WriteToLogFile_Debug("Completed with ERROR", sFuncName)
    '        WriteToLogFile(ex.Message, sFuncName)
    '        Return ex.Message
    '    End Try

    'End Function

End Class

